//查询用户
function queryUser(){

}

//帖子中的用户
//mhy-user-card mhy-article-card__user mhy-user-card-xs
//mhy-router-link mhy-user-card__link用户头像
//mhy-authentication-mark认证图标
//mhy-account-title__name用户名称
//mhy-article-type__label mhy-article-type__official官方标签
//mhy-article-card__h3帖子标题
//mhy-article-card__content内容简介
//mhy-article-card__preview图片存放区域
var concern="关注"
//获取关注列表集合
var values = $(".mhy-article-list__body>input[type=hidden]").map(function() {
    return $(this).val();
}).get();
//查询用户之间关系
async function checkRelation(fid, uid) {
    try {
        let response = await fetch('RelationServlet', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: new URLSearchParams({
                'fid': fid,
                'uid': uid
            })
        });
        let row = await response.text();
        if(row!=0){
            concern="已关注"
        }else {
            concern="关注"
        }
    } catch (error) {
        console.error('Error:', error);
    }
}

$(function (){

// 检查字符集合是否包含特定字符
    $.ajax({
        url:"QueryFiveUserServlet",
        type:"post",
        dataType:"json",
        success:function (users){

            var $list=$(".mhy-recommend-user-list-mini");
            for (var i=0;i<users.length;i++){
                let con;
                if (values.includes(users[i].uid)) {
                    con = '已关注'; // 如果包含，则设置为已关注
                } else {
                    con = '关注';   // 如果不包含，则设置为关注
                }
                var divUser="<div class=\"mhy-user-card mhy-recommend-user-list-mini__card mhy-user-card-md\">\n" +
                    "                                                <a href=\"https://www.miyoushe.com/ys/accountCenter/postList?id=282746421\" class=\"mhy-router-link mhy-user-card__link\" target=\"_blank\">\n" +
                    "                                                    <div class=\"mhy-avatar mhy-user-card__avatar mhy-avatar__md\">\n" +
                    "                                                        <img src=\"image/"+users[i].avatar+"\" class=\"mhy-avatar__img\">\n" +
                    "                                                        <!---->\n" +
                    "                                                        <div class=\"mhy-avatar__auth\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"mhy-authentication-mark\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img src=\"image/"+users[i].certification+".png\" class=\"mhy-img-icon mhy-authentication-mark__icon\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</span>\n" +
                    "                                                        </div>\n" +
                    "                                                    </div>\n" +
                    "                                                </a>\n" +
                    "                                                <div class=\"mhy-user-card__info\">\n" +
                    "                                                    <a href=\"https://www.miyoushe.com/ys/accountCenter/postList?id=282746421\" class=\"mhy-router-link mhy-account-title mhy-user-card__link\" target=\"_blank\" title=\"鮎川天理\">\n" +
                    "                                                        <span class=\"mhy-account-title__name\">"+users[i].nickname+"</span>\n" +
                    "                                                        <img src=\"image/level"+users[i].level+".png\" class=\"mhy-img-icon mhy-account-title__level\">\n" +
                    "                                                        <!---->\n" +
                    "                                                        <!---->\n" +
                    "                                                        <!---->\n" +
                    "                                                    </a>\n" +
                    "                                                    <p class=\"mhy-user-card__certification\">"+users[i].introduce+"</p>\n" +
                    "                                                    <!---->\n" +
                    "                                                    <!---->\n" +
                    "                                                </div>\n" +
                    "                                                <div class=\"mhy-follow-button mhy-user-card__follow\">\n" +
                    "                                                    <span>"+con+"</span>\n" +
                    "                                                </div>\n" +
                    "                                            </div>"


                $list.append(divUser)
            }

        }
    })
    $.ajax({
        url:"HomeAppearServlet",
        type:"post",
        dataType:"json",
        success:function (posts){

            for (var i=0;i<posts.length;i++){
                let con;
                if (values.includes(posts[i].uid)) {
                    con = '已关注'; // 如果包含，则设置为已关注
                } else {
                    con = '关注';   // 如果不包含，则设置为关注
                }
                var offical ="";
                if(posts[i].is_official=="1"){
                    offical="官方"
                }

                var $postDiv=" <div class=\"mhy-article-card\">\n" +
                    "                                            <div class=\"mhy-article-card__header\">\n" +
                    "                                                <div class=\"mhy-article-card__userinfo\">\n" +
                    "                                                    <div class=\"mhy-user-card mhy-article-card__user mhy-user-card-xs\">\n" +
                    "                                                        <a href=\"QueryPostDetail?id="+posts[i].post_id+"\" class=\"mhy-router-link mhy-user-card__link\" target=\"_blank\">\n" +
                    "                                                            <div class=\"mhy-avatar mhy-user-card__avatar mhy-avatar__xs\">\n" +
                    "                                                                <img src=\"image/"+posts[i].avatar+"\" class=\"mhy-avatar__img\">\n" +
                    "                                                                <!---->\n" +
                    "                                                                <div class=\"mhy-avatar__auth\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"mhy-authentication-mark\">\n" +//认证图标
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img src=\"image/"+posts[i].certification+".png\" class=\"mhy-img-icon mhy-authentication-mark__icon\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</span>\n" +      /*level16.png*/
                    "                                                                </div>\n" +
                    "                                                            </div>\n" +
                    "                                                        </a>\n" +
                    "                                                        <div class=\"mhy-user-card__info\">\n" +
                    "                                                            <a href=\"https://www.miyoushe.com/ys/accountCenter/postList?id=75276539\" class=\"mhy-router-link mhy-account-title mhy-user-card__link\" target=\"_blank\" title=\"原神\">\n" +
                    "                                                                <span class=\"mhy-account-title__name\">"+posts[i].nickname+"</span>\n" +
                    "                                                                <img src=\"image/level"+posts[i].level+".png\" class=\"mhy-img-icon mhy-account-title__level\">\n" +
                    "                                                                <!---->\n" +
                    "                                                                <!---->\n" +
                    "                                                                <!---->\n" +
                    "                                                            </a>\n" +
                    "                                                            <!---->\n" +
                    "                                                            <!---->\n" +
                    "                                                            <!---->\n" +
                    "                                                        </div>\n" +
                    "                                                       <div class=\"mhy-follow-button mhy-user-card__follow\"><span >"+con+"</span></div>\n" +
                    "                                                    </div>\n" +
                    "                                                    <p class=\"mhy-article-card__info\">\n" +
                    "                                                        \n" +
                    "                                                        • 官方\n" +
                    "\n" +
                    "                                                    </p>\n" +
                    "                                                    <span class=\"mhy-account-center-time__small mhy-article-card__info\"> · 原神</span>\n" +
                    "                                                </div>\n" +
                    "                                                <!---->\n" +
                    "                                                <!---->\n" +
                    "                                            </div>\n" +
                    "                                            <a href=\"QueryPostDetail?id="+posts[i].post_id+"\" class=\"mhy-router-link mhy-article-card__link\" target=\"_blank\">\n" +
                    "                                                <div class=\"mhy-article-card__title\">\n" +
                    "                                                    <div class=\"mhy-article-type mhy-article-card__type\">\n" +
                    "                                                        <!---->\n" +
                    "                                                        <span class=\"mhy-article-type__label mhy-article-type__official\">"+offical+"</span>\n" +
                    "                                                    </div>\n" +
                    "                                                    <h3 title=\"\" class=\"mhy-article-card__h3\">"+posts[i].subject+"</h3>\n" +
                    "                                                    <!---->\n" +
                    "                                                </div>\n" +
                    "                                                <div class=\"mhy-article-card__content\">"+posts[i].content+"</div>\n" +
                    "                                                <div class=\"mhy-article-card__preview\">\n" +
                    "                                                    <div preview=\"54564295\"  class=\"mhy-article-card__img\"  lazy=\"loaded\" style=\"background-image: url('image"+"/"+posts[i].cover+"');\" data-pswp-uid=\"1\">\n" +
                    "                                                        <!---->\n" +
                    "                                                    </div>\n" +
                    "                                                    <div large=\"https://upload-bbs.miyoushe.com/upload/2024/07/03/75276539/27dcffa2946c869aa503d959b9ea6f8e_4898560149043245997.png\" preview=\"54564295\" class=\"mhy-article-card__thumb\" data-pswp-uid=\"2\"></div>\n" +
                    "                                                    <span class=\"mhy-article-card__imgnum\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"12\" height=\"12\" viewBox=\"0 0 512 512\"><path d=\"M64 144v304h303.9V144H64zm287.9 288H80V160h271.9v272z\" fill=\"currentColor\"/><path d=\"M448 64H144v64h16V80h272v272h-48v16h64z\" fill=\"currentColor\"/></svg>\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>+2</span>\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</span>\n" +
                    "                                                </div>\n" +
                    "                                            </a>\n" +
                    "                                            <div class=\"mhy-article-card__footer\">\n" +
                    "                                                <!---->\n" +
                    "                                                <!---->\n" +
                    "                                                <div class=\"mhy-article-card__data\">\n" +
                    "                                                    <!---->\n" +
                    "                                                    <a href=\"QueryPostDetail?id="+posts[i].post_id+"\" class=\"mhy-router-link mhy-article-card__data-item\" target=\"_blank\">\n" +
                    "                                                        <img class=\"mhy-icon iconfont icon-liuyanshu\" src='image/评论h.png'>\n" +
                    "                                                     <!--评论数-->   <span>"+posts[i].max_floor+"</span>\n" +
                    "                                                    </a>\n" +
                    "                                                    <div class=\"mhy-article-card__data-item\">\n" +
                    "                                                        <div class=\"mhy-heart-click\">\n" +
                    "                                                            <img class=\"mhy-symbol-icon mhy-heart-click__icon\" src='image/点赞.png'>\n" +
                    "                                                                \n" +
                    "                                                            \n" +
                    "                                                        </div>\n" +
                    "                                                      <!---->  <span>"+posts[i].clickCount+"</span>\n" +
                    "                                                    </div>\n" +
                    "                                                </div>\n" +
                    "                                            </div>\n" +
                    "                                        </div>";
                var $ulBody=$(".mhy-article-list__body");
                $ulBody.append($postDiv);
            }
        }
    })
    //查询话题
    $.ajax({
        url:"QueryFiveTopicsServlet",
        type:"post",
        dataType:"json",
        success:function (topics){
            var $list=$(".mhy-topic-list");
            for (var i=0;i<topics.length;i++){

                var $div="<div class=\"mhy-topic-card mhy-topic-list__card mhy-topic-card-sm\">\n" +
                    "                                                <a href=\"QueryTopicPostServlet?id="+topics[i].id+"\" class=\"mhy-router-link mhy-topic-card__link\" target=\"_blank\">\n" +
                    "                                                    <div class=\"mhy-topic-card__cover\">\n" +
                    "                                                        <img src=\"image/"+topics[i].cover+"\" class=\"mhy-topic-card__img\">\n" +
                    "                                                    </div>\n" +
                    "                                                </a>\n" +
                    "                                                <div class=\"mhy-topic-card__info\">\n" +
                    "                                                    <a href=\"QueryTopicPostServlet?id="+topics[i].id+"\" class=\"mhy-router-link mhy-topic-card__link\" target=\"_blank\">\n" +
                    "                                                        <p class=\"mhy-topic-card__name\">"+topics[i].name+"</p>\n" +
                    "                                                    </a>\n" +
                    "                                                    <p class=\"mhy-topic-card__desc\"></p>\n" +
                    "                                                </div>\n" +
                    "                                            </div>"
                $list.append($div)
            }

        }
    })

})
var start=5;
function supplementPost(){
    $.ajax({
        url: "SupplementPostServlet",
        data: {"start":start},
        type: "post",
        dataType: "json",
        success:function (posts){
            for (var i=0;i<posts.length;i++){

                let con;
                if (values.includes(posts[i].uid)) {
                    con = '已关注'; // 如果包含，则设置为已关注
                } else {
                    con = '关注';   // 如果不包含，则设置为关注
                }

                var offical ="";
                if(posts[i].is_official=="1"){
                    offical="官方"
                }
                var $postDiv=" <div class=\"mhy-article-card\">\n" +
                    "                                            <div class=\"mhy-article-card__header\">\n" +
                    "                                                <div class=\"mhy-article-card__userinfo\">\n" +
                    "                                                    <div class=\"mhy-user-card mhy-article-card__user mhy-user-card-xs\">\n" +
                    "                                                        <a href=\"https://www.miyoushe.com/ys/accountCenter/postList?id=75276539\" class=\"mhy-router-link mhy-user-card__link\" target=\"_blank\">\n" +
                    "                                                            <div class=\"mhy-avatar mhy-user-card__avatar mhy-avatar__xs\">\n" +
                    "                                                                <img src=\"image/"+posts[i].avatar+"\" class=\"mhy-avatar__img\">\n" +
                    "                                                                <!---->\n" +
                    "                                                                <div class=\"mhy-avatar__auth\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"mhy-authentication-mark\">\n" +//认证图标
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img src=\"image/"+posts[i].certification+".png\" class=\"mhy-img-icon mhy-authentication-mark__icon\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</span>\n" +      /*level16.png*/
                    "                                                                </div>\n" +
                    "                                                            </div>\n" +
                    "                                                        </a>\n" +
                    "                                                        <div class=\"mhy-user-card__info\">\n" +
                    "                                                            <a href=\"https://www.miyoushe.com/ys/accountCenter/postList?id=75276539\" class=\"mhy-router-link mhy-account-title mhy-user-card__link\" target=\"_blank\" title=\"原神\">\n" +
                    "                                                                <span class=\"mhy-account-title__name\">"+posts[i].nickname+"</span>\n" +
                    "                                                                <img src=\"image/level"+posts[i].level+".png\" class=\"mhy-img-icon mhy-account-title__level\">\n" +
                    "                                                                <!---->\n" +
                    "                                                                <!---->\n" +
                    "                                                                <!---->\n" +
                    "                                                            </a>\n" +
                    "                                                            <!---->\n" +
                    "                                                            <!---->\n" +
                    "                                                            <!---->\n" +
                    "                                                        </div>\n" +
                    "                                                       <div class=\"mhy-follow-button mhy-user-card__follow\"><span >"+con+"</span></div>\n" +
                    "                                                    </div>\n" +
                    "                                                    <p class=\"mhy-article-card__info\">\n" +
                    "                                                        \n" +
                    "                                                        • 官方\n" +
                    "\n" +
                    "                                                    </p>\n" +
                    "                                                    <span class=\"mhy-account-center-time__small mhy-article-card__info\"> · 原神</span>\n" +
                    "                                                </div>\n" +
                    "                                                <!---->\n" +
                    "                                                <!---->\n" +
                    "                                            </div>\n" +
                    "                                            <a href=\"QueryPostDetail?id="+posts[i].post_id+"\" class=\"mhy-router-link mhy-article-card__link\" target=\"_blank\">\n" +
                    "                                                <div class=\"mhy-article-card__title\">\n" +
                    "                                                    <div class=\"mhy-article-type mhy-article-card__type\">\n" +
                    "                                                        <!---->\n" +
                    "                                                        <span class=\"mhy-article-type__label mhy-article-type__official\">"+offical+"</span>\n" +
                    "                                                    </div>\n" +
                    "                                                    <h3 title=\"\" class=\"mhy-article-card__h3\">"+posts[i].subject+"</h3>\n" +
                    "                                                    <!---->\n" +
                    "                                                </div>\n" +
                    "                                                <div class=\"mhy-article-card__content\">"+posts[i].content+"</div>\n" +
                    "                                                <div class=\"mhy-article-card__preview\">\n" +
                    "                                                    <div preview=\"54564295\"  class=\"mhy-article-card__img\"  lazy=\"loaded\" style=\"background-image: url('image"+"/"+posts[i].cover+"');\" data-pswp-uid=\"1\">\n" +
                    "                                                        <!---->\n" +
                    "                                                    </div>\n" +
                    "                                                    <div large=\"https://upload-bbs.miyoushe.com/upload/2024/07/03/75276539/27dcffa2946c869aa503d959b9ea6f8e_4898560149043245997.png\" preview=\"54564295\" class=\"mhy-article-card__thumb\" data-pswp-uid=\"2\"></div>\n" +
                    "                                                    <span class=\"mhy-article-card__imgnum\">\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"12\" height=\"12\" viewBox=\"0 0 512 512\"><path d=\"M64 144v304h303.9V144H64zm287.9 288H80V160h271.9v272z\" fill=\"currentColor\"/><path d=\"M448 64H144v64h16V80h272v272h-48v16h64z\" fill=\"currentColor\"/></svg>\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>+2</span>\n" +
                    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t</span>\n" +
                    "                                                </div>\n" +
                    "                                            </a>\n" +
                    "                                            <div class=\"mhy-article-card__footer\">\n" +
                    "                                                <!---->\n" +
                    "                                                <!---->\n" +
                    "                                                <div class=\"mhy-article-card__data\">\n" +
                    "                                                    <!---->\n" +
                    "                                                    <a href=\"QueryPostDetail?id="+posts[i].post_id+"\" class=\"mhy-router-link mhy-article-card__data-item\" target=\"_blank\">\n" +
                    "                                                        <img class=\"mhy-icon iconfont icon-liuyanshu\" src='image/评论h.png'>\n" +
                    "                                                     <!--评论数-->   <span>"+posts[i].max_floor+"</span>\n" +
                    "                                                    </a>\n" +
                    "                                                    <div class=\"mhy-article-card__data-item\">\n" +
                    "                                                        <div class=\"mhy-heart-click\">\n" +
                    "                                                            <img class=\"mhy-symbol-icon mhy-heart-click__icon\" src='image/点赞.png'>\n" +
                    "                                                                \n" +
                    "                                                            \n" +
                    "                                                        </div>\n" +
                    "                                                      <!---->  <span>"+posts[i].clickCount+"</span>\n" +
                    "                                                    </div>\n" +
                    "                                                </div>\n" +
                    "                                            </div>\n" +
                    "                                        </div>";
                var $ulBody=$(".mhy-article-list__body");
                $ulBody.append($postDiv);

            }
        }

    })

    start=start+5;
}
//显示三秒加载动画
//点击加载更多追加帖子数据
$("#jiazai").click(function (){
    var div = $(".simple-spinner");
    var buut=$("#jiazai");
    // 如果div是隐藏的，则显示它
    buut.hide();
            div.show();

        // 设置三秒后隐藏div
        setTimeout(function() {
           div.hide()
            buut.show();
            // 在div隐藏后执行的函数
            supplementPost();
        }, 1200); // 3000毫秒后执行
})
//实现发帖页面跳转
document.getElementById("fatieziB").addEventListener('click', function() {
    window.location.href = 'QueryAddPostTopicServlet'; // 目标页面的URL
});
document.getElementById("guance").addEventListener('click', function() {
    window.location.href = 'header.html'; // 目标页面的URL
});












